﻿<Page
    x:Class="Padsurface.App.Views.PadPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Padsurface.App.Views"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:views="using:Padsurface.App.Views"
    xmlns:uc="using:Padsurface.App.UserControls"
    mc:Ignorable="d"
    d:DataContext="{Binding Source={d:DesignInstance Type=views:DesignTimeData, IsDesignTimeCreatable=True}}">

    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition />
        </Grid.RowDefinitions>
        
        <Grid Margin="120,0,120,0" VerticalAlignment="Bottom">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <uc:TimerUserControl Caption="Playing" Time="{Binding PlayingTime}" Visibility="{Binding IsPlaying, Converter={StaticResource booleanToVisibilityConverter}}"
                                 MinWidth="300"></uc:TimerUserControl>
            
            <uc:TimerUserControl Caption="Recording" Time="{Binding RecordingPerformanceTime}" Visibility="{Binding IsRecordingPerformance, Converter={StaticResource booleanToVisibilityConverter}}" 
                                 Grid.Column="1" Margin="20,0,0,0" MinWidth="300"></uc:TimerUserControl>

            <uc:TimerUserControl Caption="Sampling" Time="{Binding SamplingTime}" Visibility="{Binding IsSampling, Converter={StaticResource booleanToVisibilityConverter}}" 
                                 Grid.Column="2" HorizontalAlignment="Right"></uc:TimerUserControl>
        </Grid>

        <uc:BeatCounterUserControl Grid.Row="1" HorizontalAlignment="Center"
                                   Beat="{Binding CurrentBeat}" Margin="20" Visibility="{Binding IsPlaying, Converter={StaticResource booleanToVisibilityConverter}}"></uc:BeatCounterUserControl>

        <GridView Grid.Row="1" Margin="0,0,0,50" ItemsSource="{Binding Sounds}" DataContext="{Binding}" 
                  d:DataContext="{Binding Source={d:DesignInstance Type=views:DesignTimeData, IsDesignTimeCreatable=True}}"
                  HorizontalAlignment="Center" VerticalAlignment="Center" SelectionMode="None" CanReorderItems="True" AllowDrop="True">
            <GridView.ItemTemplate>
                <DataTemplate>
                    <Border Padding="20">
                        <Button Content="{Binding Name}" Width="240" Height="240" Command="{Binding StartPlayingCommand}" CommandParameter="{Binding}"
                            Background="{Binding Mode=OneTime, Converter={StaticResource backgroundToRandomColorConverter}}" ClickMode="Press" >
                        </Button>
                    </Border>
                </DataTemplate>
            </GridView.ItemTemplate>
        </GridView>

        <RichTextBlock Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,20,100" 
                       Width="360"
                       Visibility="{Binding IsMicrophoneDisabled, Converter={StaticResource booleanToVisibilityConverter}}">
            <Paragraph>
                <InlineUIContainer>
                    <TextBlock Style="{StaticResource PageSubheaderTextStyle}">Microphone</TextBlock>
                </InlineUIContainer>
            </Paragraph>
            <Paragraph>
                <InlineUIContainer>
                    <TextBlock Style="{StaticResource BasicTextStyle}">This app needs permission to use your microphone.</TextBlock>
                </InlineUIContainer>
            </Paragraph>
            <Paragraph>
                <LineBreak />
                <InlineUIContainer>
                    <TextBlock Style="{StaticResource BasicTextStyle}">Your microphone is currently turned off.</TextBlock>
                </InlineUIContainer>
                <LineBreak />
                <InlineUIContainer>
                    <TextBlock Style="{StaticResource BasicTextStyle}">To change your microphone setting, open the settings charm and tap permissions.</TextBlock>
                </InlineUIContainer>
                <LineBreak />
            </Paragraph>
            <Paragraph>
                <InlineUIContainer>
                    <TextBlock Style="{StaticResource BasicTextStyle}">Then tap Sample again to start using your microphone.</TextBlock>
                </InlineUIContainer>
            </Paragraph>
        </RichTextBlock>
    </Grid>

    <Page.BottomAppBar>
        <AppBar IsOpen="True" Margin="0,4,0,-4">
            <Grid>
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
                    <uc:AppBarToggleButton IsChecked="{Binding IsPlayingToggled, Mode=TwoWay}" Style="{StaticResource PlayAppBarButtonStyle}" />
                    <uc:AppBarToggleButton IsChecked="{Binding IsRecordingPerformanceToggled, Mode=TwoWay}" Style="{StaticResource AudioAppBarButtonStyle}" AutomationProperties.Name="Record" />
                    <uc:AppBarToggleButton IsChecked="{Binding IsLoopEnabled, Mode=TwoWay}" Style="{StaticResource RepeatAllAppBarButtonStyle}" AutomationProperties.Name="Loop" />
                    <Button Style="{StaticResource ClockAppBarButtonStyle}" AutomationProperties.Name="Tempo" Tapped="TempoButtonTapped" />
                    <Line X1="0" Y1="60" Margin="20,10,20,0" StrokeThickness="3" Stroke="{StaticResource AppBarItemDisabledForegroundThemeBrush}" />
                    <Button Style="{StaticResource SaveAppBarButtonStyle}" Command="{Binding SaveSongCommand}" />
                </StackPanel>
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                    <uc:AppBarToggleButton IsChecked="{Binding IsSamplingToggled, Mode=TwoWay}" Style="{StaticResource MicrophoneAppBarButtonStyle}" AutomationProperties.Name="Sample" />
                    <Button Command="{Binding AddSoundCommand}" Style="{StaticResource AddAppBarButtonStyle}" />
                    <Button Style="{StaticResource EditAppBarButtonStyle}" IsEnabled="False" />
                </StackPanel>
            </Grid>
        </AppBar>
    </Page.BottomAppBar>
</Page>